#include <iostream>
using namespace std;

#include "cv.h"
#include "highgui.h"
#include "opencv2/opencv.hpp"
#include "opencv2/photo.hpp"

int main(int argc, char* argv[])
{
    if (argc < 3) {
        cerr << "invalid arg count" << endl;
        return  1;
    }
    
    const char* dstImage = argv[1];
    const char* srcImage = argv[2];
    int dstX;
    int dstY;
    cout << "src: " << srcImage << "\n";
    cout << "dst: " << dstImage << "\n";
   

    cv::Mat src = cv::imread(srcImage);
    cout << "src size: " << src.cols << ", " << src.rows << endl;
    cv::Mat mask = 255*cv::Mat::ones(cvSize(src.cols, src.rows), CV_8U);
    cout << "mask size: " << mask.cols << ", " << mask.rows << endl;
    cv::Mat dst = cv::imread(dstImage);
    cout << "dst size: " << dst.cols << ", " << dst.rows << endl;
    cv::Mat ret(dst.rows, dst.cols, dst.depth());
    cout << "ret size: " << ret.cols << ", " << ret.rows << endl;

    if (argc == 5) {
        dstX = atoi(argv[3]);
        dstY = atoi(argv[4]);
    }
    else {
        dstX = dst.cols / 2;
        dstY = dst.rows / 2;
    }
    cout << "pos: (" << dstX << ", " << dstY << ")" << endl;

    cv::seamlessClone(src, dst, mask, cvPoint(dstX, dstY), ret, cv::MONOCHROME_TRANSFER);

    cout << "clone finished" << endl;

    cv::imwrite("ret.bmp", ret);

    return 0;
}